package com.mudrov.primenumbers;

import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;

import static org.junit.Assert.assertArrayEquals;

public class PrimeNumberGetter {
    Integer[] arrayWithNumbers;
    int positionOf53PrimeNumber;
    @Before
    public void addPrimeNumbers() {
        arrayWithNumbers = new Integer[]{
                2, 3, 5, 7, 11, 13, 17, 19, 23,
                29, 31, 37, 41, 43, 47, 53, 59,
                61, 67, 71, 73, 79, 83, 89, 97};
        positionOf53PrimeNumber = 15;
    }

    @Test
    public void testPrimeNumbersFromZero() throws Exception {
        PrimeNumbersGetter testGetter = new PrimeNumbersGetter(100);
        testGetter.executeAtkinBlock(1,(int)Math.sqrt(100));
        testGetter.lastPhase();
        assertArrayEquals(arrayWithNumbers, testGetter.getSetPrimeNumbers().toArray());
    }
    @Test
    public void testPrimeNumbersFromValue() throws Exception {
        PrimeNumbersGetter testGetter = new PrimeNumbersGetter(100);
        testGetter.executeAtkinBlock(1,(int)Math.sqrt(100));
        testGetter.lastPhase();
        assertArrayEquals(Arrays.copyOfRange(arrayWithNumbers,positionOf53PrimeNumber,arrayWithNumbers.length),
                testGetter.getSetPrimeNumbers(50).toArray());
    }
}
